Esp32Platform reinitializing EEPROM multiple times causing it to forget staged EEPROM changes #196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For the ESP32, you cannot call EEPROM.begin(size) multiple times, and get the same data buffer back. Each call re-creates the in-memory data array mirror of the flash contents. The ESP32 arduino library the code is clearing EEPROM emulation data array is here;
https://github.com/espressif/arduino-esp32/blob/02c3ec01cca90d3b84398791656599d8cb3bb668/libraries/EEPROM/src/EEPROM.cpp#L128
The result is that when loading a program from ETS doesn't work because it calls Esp32Platform::getEepromBuffer() several times (calling EEPROM.begin(size)), causing it for forget all previously changed bytes.
Ideally we should could use the .length() to determine if the EEPROM was initialized properly.
However this was broken until quite recently espressif/arduino-esp32#5775 (requiring v2.0.1+), therefore I just put a simple guard around the begin.